package cn.jn.lhm.part01;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @author lhm 2753914576@qq.com
 * @time 2023/4/5 - 19:36
 **/
public class ChannelTransfer {
    public static void main(String[] args) {
        try (
                FileChannel form = new FileInputStream(ChannelTransfer.class.getResource("/").getFile() + "data.txt").getChannel();
                FileChannel to = new FileOutputStream(ChannelTransfer.class.getResource("/").getFile() + "to.txt").getChannel();
        ) {
            // 效率高，底层使用0拷贝进行优化
            form.transferTo(0, form.size(), to);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
